import { Injectable } from '@nestjs/common'
import * as path from 'path'
@Injectable()
export class PathService {
  dirname(p: string): string {
    return path.dirname(p)
  }

  extname(p: string): string {
    return path.extname(p)
  }

  format(pathObject: path.FormatInputPathObject): string {
    return path.format(pathObject)
  }
  /**
   * 判定 p 是否为一个绝对路径
   * @param p路径
   */
  isAbsolute(p: string): boolean {
    return path.isAbsolute(p)
  }

  join(...paths: string[]): string {
    return path.join(...paths)
  }

  normalize(p: string): string {
    return path.normalize(p)
  }

  parse(p: string): path.ParsedPath {
    return path.parse(p)
  }

  relative(from: string, to: string): string {
    return path.relative(from, to)
  }

  resolve(...pathSegments: string[]): string {
    return path.resolve(...pathSegments)
  }

  get sep(): string {
    return path.sep
  }
}
